package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hlw.hr_man.service.FindDeptService;
import com.hlw.hr_man.service.FuncService;
import com.hlw.hr_man.serviceImpl.FindDeptServiceImpl;
import com.hlw.hr_man.serviceImpl.FuncServiceImpl;

import net.sf.json.JSONArray;


/**
 * 找到登录用户的功能列表
 * @author 李豪
 *
 */
public class Showfuncscontroller extends HttpServlet {
	FuncService funcservice =new FuncServiceImpl();
	FindDeptService  findDeptService = new FindDeptServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		 resp.setCharacterEncoding("utf8");
	        HttpSession session=req.getSession();
	        int eid=(int) session.getAttribute("employeeid");
	        String s=funcservice.getCurrentEmployeeFuncs(eid);
	        List dept = findDeptService.getDeptments();
	        session.setAttribute("dept", dept);
	        PrintWriter pw=resp.getWriter();
	        JSONArray funcs=funcservice.getFuncs(-1,s);
	        session.setAttribute("currentfuncs", funcs);
	        pw.write(funcs.toString());
	}

}
